import { Login } from "@/views/Login";
import { useRoutes } from "react-router-dom";
import { RouteObject } from "./interface";
import { Dashboard } from "@/views/Dashboard";
import { Layout } from "@/layouts";
import { User } from "@/views/Users";
import { Permission } from "@/views/Permissions";
import { Role } from "@/views/Roles";

export const rootRouter: RouteObject[] = [
  {
    path: "/login",
    element: <Login />,
    meta: {
      requiresAuth: false,
      title: "登录页",
      key: "login",
    },
  },
  {
    path: "/",
    element: <Layout />,
    children: [
      {
        path: "dashboard",
        element: <Dashboard />,
        meta: { requiresAuth: true, title: "首页", key: "dashboard" },
      }, // 默认跳转
      {
        path: "users",
        element: <User />,
        meta: { requiresAuth: true, title: "用户管理", key: "user" },
      },
      {
        path: "roles",
        element: <Role />,
        meta: { requiresAuth: true, title: "角色管理", key: "user" },
      },
      {
        path: "permissions",
        element: <Permission />,
        meta: { requiresAuth: true, title: "权限管理", key: "user" },
      },
    ],
  },
];

const Router = () => {
  const routes = useRoutes(rootRouter);
  return routes;
};

export default Router;
